package com.xiaoyang.lotterysystem.dao.mapper;

import com.xiaoyang.lotterysystem.dao.dataobject.WinningRecordDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface WinningRecordMapper {

    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    int batchInsert(@Param("items") List<WinningRecordDO> winningRecordDOList);

    @Select("select * from winning_record where activity_id = #{activityId}")
    List<WinningRecordDO> selectByActivityId(@Param("activityId") Long activityId);

    @Select("select count(1) from winning_record where activity_id = #{activityId} and prize_id = #{prizeId}")
    Integer countByAPId(@Param("activityId") Long activityId, @Param("prizeId") Long prizeId);

    /**
     * 删除活动 或者 奖品下的中奖记录
     * @param activityId
     * @param prizeId
     */
    void deleteRecords(@Param("activityId") Long activityId, @Param("prizeId") Long prizeId);

    /**
     * 查询活动 或者 奖品下的中奖记录
     * @param activityId
     * @param prizeId
     * @return
     */
    List<WinningRecordDO> selectByActivityIdOrPrizeId(@Param("activityId") Long activityId,
                                                      @Param("prizeId") Long prizeId);
}
